package com.nintendo.proxy;

import com.nintendo.Star;
import com.nintendo.entity.BigStar;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyUtil {
    public static Star createProxy(BigStar bigStar){
        Star star = (Star) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(),
                new Class[]{Star.class},
                (proxy, method, args) -> {
                    System.out.println("before");
                    method.invoke(bigStar,args);
                    System.out.println("after");
                    return method.invoke(bigStar,args);
                });
        return star;
    }
}
